﻿using System.Linq;
using RealEstate.Models;
using System.Collections.Generic;
namespace RealEstate
{
    public partial class StateEntities
    {
        private DataClassesDataContext dataContext = new DataClassesDataContext();

        public void Add(State item)
        {
            dataContext.States.InsertOnSubmit(item);
            dataContext.SubmitChanges();
        }

        public void Update(State item)
        {
            var updateItem = (from c in dataContext.States where c.Id == item.Id select c).FirstOrDefault();
            dataContext.SubmitChanges();
        }

        public void Delete(int id)
        {
            var item = (from c in dataContext.States where c.Id == id select c).FirstOrDefault();
            dataContext.States.DeleteOnSubmit(item);
            dataContext.SubmitChanges();
        }

        public State GetById(int id)
        {
            var item = (from c in dataContext.States where c.Id == id select c).FirstOrDefault();
            return item;
        }

        public IQueryable<City> GetCityById(int id)
        {
            var item = (from c in dataContext.Cities where c.StateId == id select c);
            return item;
        }

        public List<State> GetAll()
        {
            return dataContext.States.OrderBy(c => c.Id).ToList();
        }
    }
}